package com.chixing.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chixing.commons.ServerResponse;
import com.chixing.mapper.AddressMapper;
import com.chixing.pojo.Address;
import com.chixing.service.IAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AddressServiceImpl implements IAddressService {

    @Autowired
    private AddressMapper addressMapper;

    @Override
    public ServerResponse getAddressByUserId(Integer userId) {
        QueryWrapper<Address> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        List<Address> addressesList = addressMapper.selectList(queryWrapper);
        if (addressesList!=null)
            return ServerResponse.success("查询地址成功",addressesList);
        else
            return ServerResponse.fail("查询地址失败",null);
    }

    @Override
    public Address getById(Integer addressId) {
        return addressMapper.selectById(addressId);
    }
}
